package com.tsn.service.impl;

import com.tsn.common.Result;
import com.tsn.service.FileService;
import com.tsn.util.FileUtils;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *
 * </p>
 *
 * @author tsn
 * @since 2021/8/18
 */
@Service
public class FileServiceImpl implements FileService {
//    private  final static String rootPath = "D:/myFile/zjcentury";
        private  final static String rootPath = "/zjcentury";

    @Override
    public Result fileUpload(MultipartFile file) {
        FileUtils.fileUpload(file, file.getOriginalFilename(), rootPath);
        return Result.success(file.getOriginalFilename());
    }

    @Override
    public Result upload(MultipartFile[] files) {
        List<String> list=new ArrayList<>();
        System.out.println(files);
        for(MultipartFile file:files){
            FileUtils.fileUpload(file, file.getOriginalFilename(), rootPath);
            list.add(file.getOriginalFilename());
        }
        return Result.success(list);
    }
}
